app.controller('indexCtrl',function($scope,$http){
	$http.get('../php/index.php').success(function (data){
		$scope.totalArr = data;
		//定义一个数组存储 商品的类型
		$scope.kinds = [];
		for(var i = 0;i<data.length;i++){
//			console.log(data[i].kind);
				if($.inArray(data[i].kind, $scope.kinds)==-1){
					$scope.kinds.push(data[i].kind)
				}		
		}
			console.log($scope.kinds);//$scope.kinds=["meat", "fruit", "sea", "milk", "photo"]
			
			//拿到商品分类(kind)以后,要根据kind类型进行筛选
			$scope.goods1 = []
			for(var i = 0;i<$scope.kinds.length;i++){
				$http.get('../php/kind.php?kind='+$scope.kinds[i]).success(function(data){
					//拿到的是一个以kind种类区分的数组
					$scope.goods1.push(data);
				
				})
			}
				console.log($scope.goods1);
	})
	
	
			//轮播图
	//点击右键图片开始滚动
		var index = 0;
		var right = document.querySelector('.lb-right');
		var contents = document.querySelectorAll('.lb-content')
		right.onclick = function() {
			if(index == 4) {
				index = 0;
			} else {
				index++;
			}
			for(var i = 0; i < contents.length; i++) {
				contents[i].style.display = 'none';
			}
			contents[index].style.display = 'block';
			ball(index);
		}
		//点击左键图片向左滚动
		var left = document.querySelector('.lb-left');
		left.onclick = function() {
			if(index <= 0) {
				index = 4;
			} else {
				index--;
			}
			for(var i = 0; i < contents.length; i++) {
				contents[i].style.display = 'none';
			}
			contents[index].style.display = 'block';
			ball(index);
		}
		//创建计时器让大图滚动起来
		var timmer = setInterval(right.onclick, 1000);
		//当鼠标移入的时候大图滚动停止
		var wrap = document.querySelector('.lb-wrap');
		wrap.onmouseenter = function() {
			clearInterval(timmer);
		};
		//当鼠标移出时,开始大图滚动
		wrap.onmouseleave = function() {
			timmer = setInterval(right.onclick, 1000);
		};
		//添加下边的小圆函数
		function ball(a) {
			for(var j = 0; j < lis.length; j++) {
				if(j == a) {
					lis[j].style.backgroundColor = 'green';
					lis[j].style.opacity=1;
				} else {
					lis[j].style.backgroundColor = '#000';
					lis[j].style.opacity=0.2;
				}

			}
		}

		var lis = document.querySelectorAll('.lb-page li');
		lis[0].style.backgroundColor = 'green';
		for(var j = 0; j < lis.length; j++) {
			lis[j].onmouseenter = function() {
				for(var k=0;k<contents.length;k++){
					if(this==lis[k]){
						contents[k].style.display = 'block';
						index = k;
						ball(k);
					}else{
						contents[k].style.display = 'none';
					}
				}

			}
		}

	
//	礼拜五商品列表轮播图
		
		var mySwiper = new Swiper('.swiper-container', {
				direction: 'horizontal',
				loop: true,
				// 如果需要分页器
				pagination: '.swiper-pagination',
				//点击swiper-pagination切换图片
				paginationClickable: true,
				//自动播放.多长时间播放下一张图
				autoplay: 3000,

				//用户操作swiper之后，是否禁止autoplay。默认为true：停止
				autoplayDisableOnInteraction: false,

				//grabCursor 设置为true时，鼠标覆盖Swiper时指针会变成手掌形状，拖动时指针会变成抓手形状。（根据浏览器形状有所不同.
				grabCursor: true,
				//把一张完整的图换掉需要的时间
				speed: 500,
				//动画效果(cube fade overflow flip)
				effect: 'slide',
				//调函数，swiper从一个slide过渡到另一个slide结束时执行。
				onSlideChangeEnd: function(swiper) {
					//console.log(swiper.activeIndex) //切换结束时，告诉我现在是第几个slide
				}
			});
//	
//	
	
			var time = setInterval(function(){
				var days,hour,minute,second;
				//获取2017年6月30日14时0:00;
				var tomorrow = new Date(2017,5,30,14,0,0);
				var now = new Date();
				var res1 = tomorrow - now;
//				var days = Math.floor(res1/1000/60)
				var days = Math.floor(res1 /86400000);
				var res2 = res1 - days*86400000;
				hour = Math.floor(res2 /1000/60/60);
				var res3 = res2 - hour * 3600000;
				minute = Math.floor(res3/1000/60%60);
				var res4 = res3 - minute * 60000
				second = Math.floor(res4/1000);
////			console.log(days,hour,minute,second);
			var day = days+'天';
				$('.kind-down span').eq(1).html(day);
				$('.kind-down span').eq(2).html(hour);
				$('.kind-down span').eq(3).html(minute);
				$('.kind-down span').eq(4).html(second);
			},1000);	

	
	
		})
	
	
	

